<div class="hot-show" style="display: none;">

    <form class="layui-form layui-form-pane" style="padding: 10px;" action="">
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">小说ID</label>
            <div class="layui-input-block">
                <textarea id="nIds" placeholder="请输入id，并用半角逗号分隔，如：1,2,3,4,5,6" class="layui-textarea"></textarea>
            </div>
        </div>
    </form>

</div>
<script>
    layui.config({
        base: '/static/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index','table'],function () {
        var $ = layui.$
            ,admin = layui.admin
            ,table = layui.table
            ,form = layui.form;

        table.render({
            elem: '#LAY-novel-heat'
            , url: '/website/bookshelfNovels?agent_id={$agent_id}&type={$type}'
            , response: {
                statusCode: 1 //规定成功的状态码，本来是：0，现在统一改为1
            }
            , toolbar: '#toolbarHeat' //开启头部工具栏，并为其绑定左侧模板
            , defaultToolbar: false
            , page: true //开启分页
            , limit: 10
            , cols: [[
                {type: 'checkbox'}
                , {field: 'id', width: 80, title: 'ID'}
                , {field: 'title', title: '小说名', minWidth: 180}
                , {
                    field: 'scale', title: '评级', templet: function (d) {
                        if (d.scale === 'S') {
                            return '<span style="color: #FF5722;">S级</span>'
                        } else if (d.scale === 'A') {
                            return '<span style="color: #FFB800;">A级</span>'
                        } else if (d.scale === 'B') {
                            return '<span style="color: #01AAED;">B级</span>'
                        } else if (d.scale === 'C') {
                            return '<span style="color: #5FB878;">C级</span>'
                        } else {
                            return '';
                        }
                    }, align: 'center'
                }
                , {field: 'class', title: '频道<span lay-separator="">·</span>分类', templet: '#classTpl', align: 'center',minWidth:180}
                , {field: 'in_shelf', title: '<span lay-tips="下架则不展示">是否上架</span>', templet: function (d) {
                        if (d.in_shelf === 0) {
                            return '<span style="color: #FF5722;">绝对下架</span>';
                        } else if (d.in_shelf === 2) {
                            return '<span style="color: #FF5722;">下架</span>';
                        }else {
                            return '<span style="color: green">上架</span>';
                        }
                    }, align: 'center'}
                , {title: '操作', width: 150, align: 'center', toolbar: '#table-useradmin-admin'}
            ]]
        });


        table.on('toolbar(LAY-novel-heat)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            switch (obj.event) {
                case 'add':
                    $("#nIds").val('');
                    layer.open({
                        type: 1,
                        title:'添加热榜书籍',
                        offset: '15px',
                        area: ['35%', '300px'],
                        skin: 'layui-layer-demo', //样式类名
                        closeBtn: 0, //不显示关闭按钮
                        anim: 2,
                        shadeClose: true, //开启遮罩关闭
                        content: $('.hot-show'),
                        btn: ['确定', '取消']
                        ,yes: function(index, layero){
                            var nIds = $("#nIds").val();
                            let replacedText = nIds.replace(/，/g, ',');
                            $("#nIds").val(replacedText);
                            admin.req({
                                url: '/website/addBookshelfNovelIds'
                                , type: "POST"
                                , data: {'nIds': replacedText, 'agent_id': '{$agent_id}','type':'{$type}'}
                                , done: function (res) {
                                    layer.msg(res.data, {icon: 1, time: 1000}, function () {
                                        layer.close(index); //关闭弹层
                                        table.reload('LAY-novel-heat');
                                    });
                                },not_finish:function (res) {
                                    layer.msg(res.msg);
                                }
                            });
                        }
                    });
                    break;
                case 'del':
                    var data = checkStatus.data;
                    if (data.length === 0) {
                        layer.msg('请选择需要删除的书籍');
                        return false;
                    }
                    var ids = [];
                    for (var key in data) {
                        ids.push(data[key]['id']);
                    }
                    layer.confirm('确定批量删除这些书籍？',{title: false}, function(index){
                        admin.req({
                            url: '/website/delBookshelfNovel'
                            , type: "POST"
                            , data: {'novel_ids': ids, 'agent_id': '{$agent_id}','type':'{$type}'}
                            , done: function (res) {
                                layer.msg('删除成功', {icon: 1, time: 1000}, function () {
                                    layer.closeAll();
                                    table.reload('LAY-novel-heat');
                                });
                            }, not_finish: function (res) {
                                layer.msg(res.msg);
                            }
                        });
                    });
                    break;
            }
        });


        //监听工具条
        table.on('tool(LAY-novel-heat)', function(obj){
            var data = obj.data;
            if (obj.event === 'del'){
                layer.confirm('确认移除《'+obj.data.title+'》？', {icon: 3, title:false}, function(index){
                    admin.req({
                        url: '/website/delBookshelfNovel'
                        , type: "POST"
                        , data: {'novel_ids': [obj.data.id], 'agent_id': '{$agent_id}','type':'{$type}'}
                        , done: function (res) {
                            layer.msg('移除成功', {icon: 1, time: 1000}, function () {
                                obj.del();
                                layer.close(index);
                            });
                        },not_finish:function (res) {
                            layer.msg(res.msg);
                        }
                    });
                });
            }
        });
    });
</script>